package com.ruoyi.lxy.controller;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import lombok.RequiredArgsConstructor;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;

import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.lxy.domain.vo.TPolicyVo;
import com.ruoyi.lxy.domain.bo.TPolicyBo;
import com.ruoyi.lxy.service.ITPolicyService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 政策
 *
 * @author ruoyi
 * @date 2023-08-24
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/lxy/policy")
public class TPolicyController extends BaseController {

    private final ITPolicyService iTPolicyService;

    /**
     * 查询政策列表
     */
    @SaCheckPermission("lxy:policy:list")
    @GetMapping("/list")
    public TableDataInfo<TPolicyVo> list(TPolicyBo bo, PageQuery pageQuery) {
        return iTPolicyService.queryPageList(bo, pageQuery);
    }


    /**
     * 获取政策详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("lxy:policy:query")
    @GetMapping("/{id}")
    public R<TPolicyVo> getInfo(@NotNull(message = "主键不能为空")
                                @PathVariable Long id) {
        return R.ok(iTPolicyService.queryById(id));
    }

    /**
     * 修改政策
     */
    @SaCheckPermission("lxy:policy:edit")
    @Log(title = "政策", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody TPolicyBo bo) {
        return toAjax(iTPolicyService.updateByBo(bo));
    }
}
